package com.zjz.URLDemo01;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

//爬取
public class UrlDown {
    public static void main(String[] args) throws Exception{
        //1.下载地址
        URL url = new URL("https://gitee.com/zhangjzm");
        //2.连接到这个资源  HTTP
        HttpURLConnection   urlConnection   =  (HttpURLConnection)url.openConnection();
        //输入流
        InputStream inputStream = urlConnection.getInputStream();
        //文件流
        FileOutputStream fos = new FileOutputStream("paqu.html");

        //字节形式传输
        byte[] buffer = new byte[1024];
        int len;
        while((len=inputStream.read(buffer))!=-1){
            fos.write(buffer,0,len); //写出这个数据  -- 到fos
        }

        fos.close();
        inputStream.close();
        urlConnection.disconnect(); //断开连接

    }
}
